
// 转化当前时间戳为 YYYY-MM-DD HH:MM:SS
export function fomatMilsToDate(Mils) {
  if (Mils == null) {
    return ''
  } else {
    const date = new Date(Mils)
    const y = date.getFullYear() // 年
    let MM = date.getMonth() + 1 // 月
    MM = MM < 10 ? ('0' + MM) : MM
    let d = date.getDate() // 日
    d = d < 10 ? ('0' + d) : d
    let h = date.getHours() // 时
    h = h < 10 ? ('0' + h) : h
    let m = date.getMinutes()// 分
    m = m < 10 ? ('0' + m) : m
    let s = date.getSeconds()// 秒
    s = s < 10 ? ('0' + s) : s
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
  }
}
export function getDateTime(type) {
  var date = new Date()
  var hengGang = '-'
  var maoHao = ':'
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var curDate = date.getDate()
  var curHours = date.getHours()
  var curMinutes = date.getMinutes()
  var curSeconds = date.getSeconds()

  if (month >= 1 && month <= 9) {
    month = '0' + month
  }
  if (curDate >= 0 && curDate <= 9) {
    curDate = '0' + curDate
  }
  if (curHours >= 0 && curHours <= 9) {
    curHours = '0' + curHours
  }
  if (curMinutes >= 0 && curMinutes <= 9) {
    curMinutes = '0' + curMinutes
  }
  if (curSeconds >= 0 && curSeconds <= 9) {
    curSeconds = '0' + curSeconds
  }
  var currentdate = ''
  if (type === 'year') {
    currentdate = year
    return currentdate
  } else if (type === 'month') {
    currentdate = year + hengGang + month
    return currentdate
  } else {
    currentdate = year + hengGang + month + hengGang + curDate + ' ' + curHours + maoHao + curMinutes + maoHao + curSeconds
    return currentdate
  }
}
